﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using GUIServerConnectorAPI;
using EntityModel;
using ApplicationConfiguration;

namespace GUIServerConnector
{
    public class ServerInterface : MarshalByRefObject, IServerInterface
    {
        private TeleasistentaEntities entities;
        
        public ServerInterface()
        {
            entities = new TeleasistentaEntities(AppConfiguration.getInstance().getProperty("Database", "connectionString"));
        }

        private Sesiune getActiveSession(Guid sessionId)
        {
            Sesiune session = entities.Sesiunes.FirstOrDefault(s => s.idSesiune.Equals(sessionId));
            if (session == null)
                throw new AuthorizationException(Strings.InvalidSessionID);
            if (session.Stop_sesiune != null)
                throw new AuthorizationException(Strings.SessionExpired);
            return session;
        }

        private AccountType getAccountType(Sesiune session)
        {
            User user = entities.Users.FirstOrDefault(u => u.idUser.Equals(session.idUser));
            if (user == null)
                throw new AuthorizationException(Strings.InvalidSessionUserID);
            return (AccountType) Enum.Parse(typeof(AccountType), user.Rol);
        }

        public Pacient getPacientData(Guid sessionId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            Console.WriteLine("Acquired account type");
            switch (accountType)
            {
                case AccountType.PACIENT:
                    return entities.Pacients.Single(p => p.User.idUser.Equals(activeSession.idUser));
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }


        public Pacient getPacientData(Guid sessionId, Guid pacientId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    return entities.Pacients.Single(p => (p.idUser.Equals(activeSession.idUser)) && (p.idPacient.Equals(pacientId)));
                case AccountType.SUPRAVEGHETOR:
                    return entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId));
                case AccountType.MEDIC:
                    return entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId));
                case AccountType.INGRIJITOR:
                    return entities.Ingrijitors.Single(i => i.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId));
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }

        public List<Pacient> getPacientsData(Guid sessionId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            ICollection<Pacient> pacients = null;
            switch (accountType)
            {
                case AccountType.SUPRAVEGHETOR:
                    pacients = entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients;
                    break;
                case AccountType.MEDIC:
                    pacients = entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients;
                    break;
                case AccountType.INGRIJITOR:
                    pacients = entities.Ingrijitors.Single(i => i.idUser.Equals(activeSession.idUser)).Pacients;
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            return new List<Pacient>(pacients);
        }

        public void updatePacientData(Guid sessionId, Pacient pacientData)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    entities.Pacients.DeleteObject(entities.Pacients.Single(p => p.idPacient.Equals(pacientData.idPacient)));
                    entities.Pacients.AddObject(pacientData);
                    entities.SaveChanges();
                    break;
                //? do medics, caregivers and supervisers have the right to change the pacient's personal data?
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }

        public List<Medic> getMedicsData(Guid sessionId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    ICollection<Medic> medics = entities.Pacients.Single(p => p.idUser.Equals(activeSession.idUser)).Medics;
                    return new List<Medic>(medics);
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }

        public List<DefinitieSenzori> getSensorDefinitions(Guid sessionId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.MEDIC:
                case AccountType.SUPRAVEGHETOR:
                case AccountType.INGRIJITOR:
                case AccountType.PACIENT:
                    return new List<DefinitieSenzori>(entities.DefinitieSenzoris);
            }
            return null;
        }

        public List<ValoriSensori> getSensorData(Guid sessionId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    IEnumerable<IGrouping<DefinitieSenzori, ValoriSensori>> groupedPacientSensors = entities.Pacients.Single(p => p.idUser.Equals(activeSession.idUser)).ValoriSensoris.GroupBy(vs => vs.DefinitieSenzori);
                    List<ValoriSensori> mostRecentSensors = new List<ValoriSensori>();
                    foreach (IGrouping<DefinitieSenzori, ValoriSensori> pacientSensorGroup in groupedPacientSensors)
                    {
                        DateTime? maxMomentCitire = pacientSensorGroup.Max(vs => vs.MementCitire);
                        mostRecentSensors.Add(pacientSensorGroup.Single(vs => vs.MementCitire.Equals(maxMomentCitire)));
                    }
                    return mostRecentSensors;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }

        public List<ValoriSensori> getSensorData(Guid sessionId, List<DefinitieSenzori> sensorTypes)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    IEnumerable<IGrouping<DefinitieSenzori, ValoriSensori>> groupedPacientSensors = entities.Pacients.Single(p => p.idUser.Equals(activeSession.idUser)).ValoriSensoris.GroupBy(vs => vs.DefinitieSenzori);
                    List<ValoriSensori> mostRecentSensors = new List<ValoriSensori>();
                    foreach (IGrouping<DefinitieSenzori, ValoriSensori> pacientSensorGroup in groupedPacientSensors)
                    {
                        if (sensorTypes.Contains(pacientSensorGroup.Key))
                        {
                            DateTime? maxMomentCitire = pacientSensorGroup.Max(vs => vs.MementCitire);
                            mostRecentSensors.Add(pacientSensorGroup.Single(vs => vs.MementCitire.Equals(maxMomentCitire)));
                        }
                    }
                    return mostRecentSensors;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }


        public List<ValoriSensori> getSensorData(Guid sessionId, DateTime intervalStart, DateTime intervalEnd)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    IEnumerable<IGrouping<DefinitieSenzori, ValoriSensori>> groupedPacientSensors = entities.Pacients.Single(p => p.idUser.Equals(activeSession.idUser)).ValoriSensoris.Where(vsf => (vsf.MementCitire.Value.CompareTo(intervalStart) >= 0) && (vsf.MementCitire.Value.CompareTo(intervalEnd) < 0)).GroupBy(vs => vs.DefinitieSenzori);
                    List<ValoriSensori> sensors = new List<ValoriSensori>();
                    foreach (IGrouping<DefinitieSenzori, ValoriSensori> pacientSensorGroup in groupedPacientSensors)
                        sensors.AddRange(pacientSensorGroup);
                    return sensors;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }


        public List<ValoriSensori> getSensorData(Guid sessionId, List<DefinitieSenzori> sensorTypes, DateTime intervalStart, DateTime intervalEnd)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    IEnumerable<IGrouping<DefinitieSenzori, ValoriSensori>> groupedPacientSensors = entities.Pacients.Single(p => p.idUser.Equals(activeSession.idUser)).ValoriSensoris.Where(vsf => (vsf.MementCitire.Value.CompareTo(intervalStart) >= 0) && (vsf.MementCitire.Value.CompareTo(intervalEnd) < 0)).GroupBy(vs => vs.DefinitieSenzori);
                    List<ValoriSensori> sensors = new List<ValoriSensori>();
                    foreach (IGrouping<DefinitieSenzori, ValoriSensori> pacientSensorGroup in groupedPacientSensors)
                        if (sensorTypes.Contains(pacientSensorGroup.Key))
                            sensors.AddRange(pacientSensorGroup);
                    return sensors;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }


        public List<ValoriSensori> getSensorData(Guid sessionId, Guid pacientId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            ICollection<ValoriSensori> pacientSensors = null;
            switch (accountType)
            {
                case AccountType.PACIENT:
                    pacientSensors = entities.Pacients.Single(p => (p.idUser.Equals(activeSession.idUser)) && (p.idPacient.Equals(pacientId))).ValoriSensoris;
                    break;
                case AccountType.SUPRAVEGHETOR:
                    pacientSensors = entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                case AccountType.MEDIC:
                    pacientSensors = entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                case AccountType.INGRIJITOR:
                    pacientSensors = entities.Ingrijitors.Single(i => i.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            IEnumerable<IGrouping<DefinitieSenzori, ValoriSensori>> groupedPacientSensors = pacientSensors.GroupBy(vs => vs.DefinitieSenzori);
            List<ValoriSensori> mostRecentSensors = new List<ValoriSensori>();
            foreach (IGrouping<DefinitieSenzori, ValoriSensori> pacientSensorGroup in groupedPacientSensors)
            {
                DateTime? maxMomentCitire = pacientSensorGroup.Max(vs => vs.MementCitire);
                mostRecentSensors.Add(pacientSensorGroup.Single(vs => vs.MementCitire.Equals(maxMomentCitire)));
            }
            return mostRecentSensors;
        }


        public List<ValoriSensori> getSensorData(Guid sessionId, Guid pacientId, List<DefinitieSenzori> sensorTypes)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            ICollection<ValoriSensori> pacientSensors = null;
            switch (accountType)
            {
                case AccountType.PACIENT:
                    pacientSensors = entities.Pacients.Single(p => (p.idUser.Equals(activeSession.idUser)) && (p.idPacient.Equals(pacientId))).ValoriSensoris;
                    break;
                case AccountType.SUPRAVEGHETOR:
                    pacientSensors = entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                case AccountType.MEDIC:
                    pacientSensors = entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                case AccountType.INGRIJITOR:
                    pacientSensors = entities.Ingrijitors.Single(i => i.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            IEnumerable<IGrouping<DefinitieSenzori, ValoriSensori>> groupedPacientSensors = pacientSensors.GroupBy(vs => vs.DefinitieSenzori);
            List<ValoriSensori> mostRecentSensors = new List<ValoriSensori>();
            foreach (IGrouping<DefinitieSenzori, ValoriSensori> pacientSensorGroup in groupedPacientSensors)
            {
                if (sensorTypes.Contains(pacientSensorGroup.Key))
                {
                    DateTime? maxMomentCitire = pacientSensorGroup.Max(vs => vs.MementCitire);
                    mostRecentSensors.Add(pacientSensorGroup.Single(vs => vs.MementCitire.Equals(maxMomentCitire)));
                }
            }
            return mostRecentSensors;
        }


        public List<ValoriSensori> getSensorData(Guid sessionId, Guid pacientId, DateTime intervalStart, DateTime intervalEnd)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            ICollection<ValoriSensori> pacientSensors = null;
            switch (accountType)
            {
                case AccountType.PACIENT:
                    pacientSensors = entities.Pacients.Single(p => (p.idUser.Equals(activeSession.idUser)) && (p.idPacient.Equals(pacientId))).ValoriSensoris;
                    break;
                case AccountType.SUPRAVEGHETOR:
                    pacientSensors = entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                case AccountType.MEDIC:
                    pacientSensors = entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                case AccountType.INGRIJITOR:
                    pacientSensors = entities.Ingrijitors.Single(i => i.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            IEnumerable<IGrouping<DefinitieSenzori, ValoriSensori>> groupedPacientSensors = pacientSensors.Where(vsf => (vsf.MementCitire.Value.CompareTo(intervalStart) >= 0) && (vsf.MementCitire.Value.CompareTo(intervalEnd) < 0)).GroupBy(vs => vs.DefinitieSenzori);
            List<ValoriSensori> mostRecentSensors = new List<ValoriSensori>();
            foreach (IGrouping<DefinitieSenzori, ValoriSensori> pacientSensorGroup in groupedPacientSensors)
                mostRecentSensors.AddRange(pacientSensorGroup);
            return mostRecentSensors;
        }


        public List<ValoriSensori> getSensorData(Guid sessionId, Guid pacientId, List<DefinitieSenzori> sensorTypes, DateTime intervalStart, DateTime intervalEnd)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            ICollection<ValoriSensori> pacientSensors = null;
            switch (accountType)
            {
                case AccountType.PACIENT:
                    pacientSensors = entities.Pacients.Single(p => (p.idUser.Equals(activeSession.idUser)) && (p.idPacient.Equals(pacientId))).ValoriSensoris;
                    break;
                case AccountType.SUPRAVEGHETOR:
                    pacientSensors = entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                case AccountType.MEDIC:
                    pacientSensors = entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                case AccountType.INGRIJITOR:
                    pacientSensors = entities.Ingrijitors.Single(i => i.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).ValoriSensoris;
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            IEnumerable<IGrouping<DefinitieSenzori, ValoriSensori>> groupedPacientSensors = pacientSensors.Where(vsf => (vsf.MementCitire.Value.CompareTo(intervalStart) >= 0) && (vsf.MementCitire.Value.CompareTo(intervalEnd) < 0)).GroupBy(vs => vs.DefinitieSenzori);
            List<ValoriSensori> mostRecentSensors = new List<ValoriSensori>();
            foreach (IGrouping<DefinitieSenzori, ValoriSensori> pacientSensorGroup in groupedPacientSensors)
                if (sensorTypes.Contains(pacientSensorGroup.Key))
                    mostRecentSensors.AddRange(pacientSensorGroup);
            return mostRecentSensors;
        }


        public void addSensorData(Guid sessionId, List<ValoriSensori> sensors)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    foreach (ValoriSensori sensor in sensors)
                        entities.ValoriSensoris.AddObject(sensor);
                    entities.SaveChanges();
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }


        public void addSensorData(Guid sessionId, Guid pacientId, List<ValoriSensori> sensors)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    if (entities.Pacients.Single(p => p.idUser.Equals(activeSession.idUser)).idPacient.Equals(pacientId))
                        throw new InvalidOperationException(Strings.OperationInvalidForActiveSession);
                    break;
                case AccountType.INGRIJITOR:
                    if (entities.Ingrijitors.Single(i => i.idUser.Equals(activeSession.idUser)).Pacients.SingleOrDefault(p => p.idPacient.Equals(pacientId)) == null)
                        throw new InvalidOperationException(Strings.OperationInvalidForActiveSession);
                    break;
                case AccountType.SUPRAVEGHETOR:
                    if (entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients.SingleOrDefault(p => p.idPacient.Equals(pacientId)) == null)
                        throw new InvalidOperationException(Strings.OperationInvalidForActiveSession);
                    break;
                case AccountType.MEDIC:
                    if (entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients.SingleOrDefault(p => p.idPacient.Equals(pacientId)) == null)
                        throw new InvalidOperationException(Strings.OperationInvalidForActiveSession);
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            foreach (ValoriSensori sensor in sensors)
                entities.ValoriSensoris.AddObject(sensor);
            entities.SaveChanges();
        }

        public List<Tratamente> getTreatments(Guid sessionId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    return new List<Tratamente>(entities.Pacients.Single(p => p.idUser.Equals(activeSession.idUser)).Tratamentes);
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }

        public List<Tratamente> getTreatments(Guid sessionId, Guid pacientId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.PACIENT:
                    return new List<Tratamente>(entities.Pacients.Single(p => (p.idUser.Equals(activeSession.idUser)) && (p.idPacient.Equals(pacientId))).Tratamentes);
                case AccountType.INGRIJITOR:
                    return new List<Tratamente>(entities.Ingrijitors.Single(i => i.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).Tratamentes);
                case AccountType.SUPRAVEGHETOR:
                    return new List<Tratamente>(entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).Tratamentes);
                case AccountType.MEDIC:
                    return new List<Tratamente>(entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients.Single(p => p.idPacient.Equals(pacientId)).Tratamentes);
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
        }

        public void updateTreatments(Guid sessionId, Guid pacientId, List<Tratamente> treatments)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            switch (accountType)
            {
                case AccountType.MEDIC:
                    if (entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients.SingleOrDefault(p => p.idPacient.Equals(pacientId)) == null)
                        throw new InvalidOperationException(Strings.OperationInvalidForActiveSession);
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            foreach (Tratamente treatment in treatments)
                entities.Tratamentes.AddObject(treatment);
            entities.SaveChanges();
        }

        public List<DefiniteAlarme> getAlarmDefinitions(Guid sessionId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            ICollection<Pacient> pacients = null;
            switch (accountType)
            {
                case AccountType.SUPRAVEGHETOR:
                    pacients = entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients;
                    break;
                case AccountType.MEDIC:
                    pacients = entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients;
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            List<DefiniteAlarme> alarms = new List<DefiniteAlarme>();
            foreach (Pacient pacient in pacients)
                alarms.AddRange(pacient.DefiniteAlarmes);
            return alarms;
        }

        public List<ValoriAlarme> getAlarms(Guid sessionId)
        {
            Sesiune activeSession = getActiveSession(sessionId);
            AccountType accountType = getAccountType(activeSession);
            ICollection<Pacient> pacients = null;
            switch (accountType)
            {
                case AccountType.SUPRAVEGHETOR:
                    pacients = entities.Supraveghetors.Single(s => s.idUser.Equals(activeSession.idUser)).Pacients;
                    break;
                case AccountType.MEDIC:
                    pacients = entities.Medics.Single(m => m.idUser.Equals(activeSession.idUser)).Pacients;
                    break;
                default:
                    throw new InvalidOperationException(Strings.OperationInvalidForAccountType);
            }
            List<ValoriAlarme> alarms = new List<ValoriAlarme>();
            foreach (Pacient pacient in pacients)
                foreach (DefiniteAlarme alarmDefinition in pacient.DefiniteAlarmes)
                    alarms.AddRange(alarmDefinition.ValoriAlarmes);
            return alarms;
        }
    }
}
